<template>
  <div class="mineWallet">
    <u-nav-bar :title="'我的钱包'"></u-nav-bar>
    <div class="mineWallet__ct">
      <div class="info">
        <div class="total__detail">
          <div class="top">
            <div class="title">
              可用余额(元)
              <div class="eye" @click="showMoney = !showMoney">
                <van-icon v-show="showMoney === false" name="eye-o" />
                <van-icon v-show="showMoney === true" name="closed-eye" />
              </div>
            </div>
            <div class="money">
              {{
                showMoney === true ? (wallet.activeAmount ? Number(wallet.activeAmount).toFixed(2) : '0.00') : '****'
              }}
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, reactive, toRefs } from 'vue'
import { useRouter } from 'vue-router'
import store from '@/store/index'
import { Toast, Icon, Dialog } from 'vant'
import { FinanceWallet, UserInfo } from '@/store/user/types'
import uNavBar from '@/components/NavBar.vue'

type MineWallet = {
  wallet: FinanceWallet
  showMoney: boolean
  auditSuccess: boolean
}

export default defineComponent({
  name: 'MineWallet',
  components: {
    'u-nav-bar': uNavBar,
    'van-icon': Icon
  },
  setup() {
    const data = reactive<MineWallet>({
      wallet: {} as FinanceWallet,
      showMoney: false,
      auditSuccess: true
    })

    // 事件专区
    const router = useRouter()

    const handleGetFinanceWallet = async (data: MineWallet): Promise<void> => {
      data.wallet = await store.dispatch('user/handleGetFinanceWalletUser')
    }
    handleGetFinanceWallet(data)

    const hanleGetUserInfo = async (data: MineWallet): Promise<void> => {
      const result: any = await store.dispatch('user/handleGetUserInfo')
      if (result && result.auditStatus && result.auditStatus !== 2) {
        data.auditSuccess = false
      } else {
        data.auditSuccess = true
      }
    }

    if (router.currentRoute.value.query.auditStatus !== String(2)) {
      hanleGetUserInfo(data)
    }
    return {
      ...toRefs(data)
    }
  }
})
</script>
<style lang="scss" scope>
@import '@/style/variables.scss';
@import '@/style/mixins.scss';
.mineWallet {
  width: 100%;
  height: 100%;
  @include flex-cloumn-width-height-100;
  background-color: $background-color-base;
  &__ct {
    .info {
      width: 344px;
      margin: 0 auto;
      box-sizing: border-box;
    }
    .notice {
      width: 100%;
      height: 36px;
      text-align: center;
      line-height: 36px;
      font-size: 14px;
      color: $color-primary;
      background-color: #e4f1ff;
    }
    .total__detail {
      display: flex;
      margin-top: 15px;
      justify-content: space-between;
      align-items: center;
      width: 100%;
      height: 147px;
      background: url('../../../../assets/image/mine/wallet/total-bg.png') left top no-repeat;
      background-size: 100%;
      margin-bottom: 15px;
      .top {
        display: flex;
        flex-direction: column;
        justify-content: center;
        width: 100%;
        box-sizing: border-box;
        padding-left: 22px;
        height: 126px;
        .title {
          font-size: 12px;
          color: white;
          display: flex;
          align-items: center;
          .eye {
            width: 30px;
            height: 30px;
            font-size: 20px;
            line-height: 30px;
            margin-left: 10px;
            cursor: pointer;
          }
        }
        .money {
          font-size: 40px;
          margin-top: 20px;
          color: white;
          line-height: 40px;
        }
      }
    }
  }
}
</style>
